package com.work.service.impl;

import com.work.bean.HwStu;
import com.work.bean.HwStuAttach;
import com.work.dao.HwStuAttachDao;
import com.work.dao.HwStuDao;
import com.work.dao.impl.HwStuAttachDaoImpl;
import com.work.dao.impl.HwStuDaoImpl;
import com.work.dto.StudentHw;
import com.work.service.HwStuService;
import com.work.service.StudentService;

import java.util.ArrayList;
import java.util.List;

public class HwStuServiceImpl implements HwStuService {
    HwStuDao hwStuDao = new HwStuDaoImpl();
    HwStuAttachDao hwStuAttachDao = new HwStuAttachDaoImpl();
    StudentService studentService = new StudentServiceImpl();

    public List<HwStu> queryHwstu() {
        return hwStuDao.queryHwstu();
    }

    public HwStu queryHwstuById(Integer id) {
        return hwStuDao.queryHwstuById(id);
    }

    @Override
    public List<StudentHw> query(Integer hw_id) {
        List<StudentHw> list = new ArrayList<StudentHw>();
        List<HwStu> hwStus = hwStuDao.queryHwstuByHwId(hw_id);
        for (HwStu value: hwStus){
            int hw_stu_attach_id = hwStuAttachDao.queryHwStuAttachByHwStuId(value.getId()).getId();
            String name = studentService.queryStudentById(value.getsId()).getSname();
            String sNo = studentService.queryStudentById(value.getsId()).getsNo();
            list.add(new StudentHw(value.getId(),hw_id,value.getsId(),sNo,value.getStatus(),name,hw_stu_attach_id));
        }
        return  list;
    }
    public List<StudentHw> query1() {
        List<StudentHw> list = new ArrayList<StudentHw>();
        List<HwStu> hwStus = hwStuDao.queryHwstu();
        for (HwStu value: hwStus){
            int hw_stu_attach_id = hwStuAttachDao.queryHwStuAttachByHwStuId(value.getId()).getId();
            String name = studentService.queryStudentById(value.getsId()).getSname();
            String sNo = studentService.queryStudentById(value.getsId()).getsNo();
            list.add(new StudentHw(value.getId(),value.getHw_id(),value.getsId(),sNo,value.getStatus(),name,hw_stu_attach_id));
        }
        return  list;
    }

    public int saveHwStu(HwStu hwStu,String url) {
        hwStuDao.saveHwStu(hwStu);
        int hw_stu_id= hwStuDao.queryHwstuByTime().getId();
        hwStuAttachDao.saveHwStuAttach(new HwStuAttach(null,hw_stu_id,"0",url));
        return 0;
    }

    public int updateHwStu(HwStu hwStu) {
        return hwStuDao.updateHwStu(hwStu);
    }

    public int deleteHwstu(Integer id) {
        return hwStuDao.deleteHwstu(id);
    }
}
